package org.swift.mashup.engine.deployment.mcr;

import org.apache.axis2.context.MessageContext;
import org.swift.mashup.engine.deployment.MessageContextReader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CompositeMessageContextReader implements MessageContextReader {
	private List<MessageContextReader> readers = new ArrayList<MessageContextReader>();

	public CompositeMessageContextReader() {
	}

	public CompositeMessageContextReader(MessageContextReader... readers) {
		if ( readers != null ) {
			for (MessageContextReader reader : readers ) {
				this.addReader(reader);
			}
		}
	}

	public CompositeMessageContextReader addReader(MessageContextReader reader) {
		if ( reader != null ) {
			this.readers.add(reader);
		}
		return this;
	}

	@Override
	public Map<String, Object> createParameterMap(MessageContext context) {
		Map<String, Object> map = new HashMap<String,Object>();

		for ( MessageContextReader reader : readers ) {
			map.putAll( reader.createParameterMap(context) );
		}

		return map;
	}
}
